//package com.mapoffline.zbcx.mapoffline;
//
//import android.Manifest;
//import android.content.Context;
//import android.content.pm.PackageManager;
//import android.graphics.drawable.Drawable;
//import android.location.Location;
//import android.location.LocationListener;
//import android.location.LocationManager;
//import android.os.Bundle;
//import android.os.Environment;
//import android.support.v4.app.ActivityCompat;
//import android.support.v7.app.AppCompatActivity;
//import android.util.Log;
//import android.view.View;
//import android.widget.ImageView;
//import android.widget.Toast;
//
//import com.mapbox.mapboxsdk.overlay.UserLocationOverlay;
//import com.mapbox.mapboxsdk.tileprovider.MapTile;
//import com.mapbox.mapboxsdk.tileprovider.MapTileCache;
//import com.mapbox.mapboxsdk.tileprovider.modules.MapTileDownloader;
//import com.mapbox.mapboxsdk.tileprovider.tilesource.ITileLayer;
//import com.mapbox.mapboxsdk.tileprovider.tilesource.MBTilesLayer;
//import com.mapbox.mapboxsdk.views.MapView;
//
//import java.util.List;
//
//public class MainActivityOld extends AppCompatActivity
//{
//
//    private MapView mv;
//    private UserLocationOverlay myLocationOverlay;
//    private String currentMap = null;
//    private LocationManager locationManager;
//    private Drawable drawable;
//
//
//    public void test(final test[] value)
//    {
//        test(new test[]{});
//    }
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState)
//    {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//        mv = (MapView) findViewById(R.id.mapview);
//        final MBTilesLayer mbTileLayer = new MBTilesLayer(Environment.getExternalStorageDirectory()
//                .getPath() + "/Tencent/QQfile_recv/test3.mbtiles");
//
//        final MapTile mapTile = new MapTile("test2", 12, 1173, 1567);
//        final MapTileDownloader downloader = new MapTileDownloader(null, new MapTileCache(this),
//                null, mv);
//        new Thread()
//        {
//            @Override
//            public void run()
//            {
//                drawable  = mbTileLayer.getDrawableFromTile(downloader, mapTile, true);
//                Log.e("zcj", "Drawable=====" + drawable);
//            }
//        }.start();
//
//
//        mv.setTileSource(new ITileLayer[]{mbTileLayer});
//        mv.setScrollableAreaLimit(mbTileLayer.getBoundingBox());
//        mv.setMinZoomLevel(mv.getTileProvider().getMinimumZoomLevel());
//        mv.setMaxZoomLevel(mv.getTileProvider().getMaximumZoomLevel());
//        mv.setCenter(mv.getTileProvider().getCenterCoordinate());
//        mv.setZoom(4);
//
//        //Log.e("location", String.valueOf(mv.getUserLocation()));
//
//        mv.setUserLocationEnabled(true);
//
//        getMyLocation();
//    }
//
//    public void getMyLocation()
//    {
//        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//
//        // 获取所有可用的位置提供器
//        List<String> providerList = locationManager.getProviders(true);
//        String provider;
//        if (providerList.contains(LocationManager.GPS_PROVIDER))
//        {
//            provider = LocationManager.GPS_PROVIDER;
//        }
//        else if (providerList.contains(LocationManager.NETWORK_PROVIDER))
//        {
//            provider = LocationManager.NETWORK_PROVIDER;
//        }
//        else
//        {
//            // 当没有可用的位置提供器时,弹出Toast提示用户
//            Toast.makeText(this, "No location provider to use",
//                    Toast.LENGTH_SHORT).show();
//            return;
//        }
//        Log.e("location", provider);
//
//        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
//                PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
//                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
//        {
//            // TODO: Consider calling
//            //    ActivityCompat#requestPermissions
//            // here to request the missing permissions, and then overriding
//            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
//            //                                          int[] grantResults)
//            // to handle the case where the user grants the permission. See the documentation
//            // for ActivityCompat#requestPermissions for more details.
//            return;
//        }
//        Location location = locationManager.getLastKnownLocation(provider);
//        if (location != null)
//        {
//            // 显示当前设备的位置信息
//            showLocation(location);
//        }
//        locationManager.requestLocationUpdates(provider, 5000, 1, locationListener);
//    }
//
//    public void onClick(View view)
//    {
//        switch (view.getId())
//        {
//            case R.id.img_test:
//                ((ImageView)view).setImageDrawable(drawable);
//                break;
//        }
//    }
//
//    protected void onDestroy()
//    {
//        super.onDestroy();
//        if (locationManager != null)
//        {
//            // 关闭程序时将监听器移除
//            if (ActivityCompat.checkSelfPermission(this, Manifest.permission
//                    .ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat
//                    .checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) !=
//                    PackageManager.PERMISSION_GRANTED)
//            {
//                return;
//            }
//            locationManager.removeUpdates(locationListener);
//        }
//    }
//
//    LocationListener locationListener = new LocationListener()
//    {
//        @Override
//        public void onStatusChanged(String provider, int status, Bundle
//                extras)
//        {
//        }
//
//        @Override
//        public void onProviderEnabled(String provider)
//        {
//        }
//
//        @Override
//        public void onProviderDisabled(String provider)
//        {
//        }
//
//        @Override
//        public void onLocationChanged(Location location)
//        {
//            // 更新当前设备的位置信息
//            showLocation(location);
//        }
//    };
//
//    private void showLocation(Location location)
//    {
//        String currentPosition = "latitude is " + location.getLatitude() + "\n"
//                + "longitude is " + location.getLongitude();
////        Toast.makeText(this, "当前位置:" + currentPosition, Toast.LENGTH_SHORT).show();
//    }
//}
